package com.study.transaction.dispatch.api;

import com.study.transaction.dispatch.service.DispatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 运单系统http Api
 *
 * @author: chenhs
 * @date: Created in 14:34 2019/12/17
 **/
@RestController
@RequestMapping("/dispatch-api")
public class DispatchController {

    @Autowired
    private DispatchService dispatchService;

    /**
     * 下订单后，添加调度信息 --- 接口处理比较慢（模拟超时）
     * @param orderId
     * @return
     * @throws InterruptedException
     */
    @GetMapping("/dispatch")
    public String dispatch(String orderId) throws Exception {
        //此处模拟业务超时，接口调用者会认为超时
        Thread.sleep(3000L);
        //将外卖订单分配给送餐小哥
        dispatchService.dispatch(orderId);

        return "ok";
    }

}
